#!/usr/bin/env python3
# -*- coding: utf-8 -*-

products = [["iphone", 68888], ["MacPro", 14800], ["XiaoMi6", 2499],
            ["Coffee", 31], ["Book", 60], ["Nike", 699]]
cart = []
total = 0

while True:
    choices = [p[0] for p in products]
    for index, product in enumerate(choices, 1):
        print('[{}]{:>15}'.format(index, product))

    the_choice = input('Your choice: [q] to exit >> ')
    if the_choice == 'q':
        break
    try:
        the_choice = int(the_choice) - 1
    except ValueError:
        print('Use above index !')
        continue
    else:
        if the_choice > len(choices):
            print('Your choice should under {} !'.format(len(choices) + 1))
            continue
        else:
            cart.append(products[the_choice])

title = 'You select product'.center(30, '-')
print(title)
for pro, pri in cart:
    print('{}{:>20}$'.format(pro, pri))
    total += pri
print('Total: {}$'.format(total))

# 购买商品的时候，单价没有友好的展示出来